package de.hsos.samcomm.common.i18n;

import java.util.Locale;
import java.util.ResourceBundle;
import javax.faces.bean.RequestScoped;

@RequestScoped
public class I18nFacade {

    private static Locale START_LANGUAGE = Locale.getDefault();
    private static I18nFacade instance = new I18nFacade();
    private String baseName = "de.hsos.resources.LabelsBundle";
    private Locale currentLocale;
    private ResourceBundle currentResourceBundle;

    public I18nFacade() {
        this.setCurrentLocal(START_LANGUAGE);
    }

    public static I18nFacade getInstance() {
        return instance;
    }

    public final void setCurrentLocal(Locale local) {
        this.currentLocale = local;
        this.setCurrentResourceBundle(this.baseName);
    }

    public Locale getCurrentLocale() {
        return currentLocale;
    }
    
    public void setCurrentResourceBundle(String baseName) {
        this.currentResourceBundle =
                ResourceBundle.getBundle(baseName, this.currentLocale);
        this.baseName = baseName;
    }

    public String getString(String key) {
        return this.currentResourceBundle.getString(key);
    }
//    public String getString(String key, Object[] arguments) {
//        MessageFormat format = new MessageFormat("");
//        format.setLocale(this.currentLocale);
//        format.applyPattern(this.currentResourceBundle.getString(key));
//        return format.format(arguments);
//    }
//
//    public String getCurrency(Double number) {
//        NumberFormat numberFormatter =
//                NumberFormat.getCurrencyInstance(this.currentLocale);
//        return numberFormatter.format(number);
//    }
//
//    public String getInteger(Integer number) {
//        NumberFormat numberFormatter =
//                NumberFormat.getIntegerInstance(this.currentLocale);
//        return numberFormatter.format(number);
//    }
//
//    public String getNumber(Integer number) {
//        NumberFormat numberFormatter =
//                NumberFormat.getNumberInstance(this.currentLocale);
//        return numberFormatter.format(number);
//    }
//
//    public String getPercent(Double number) {
//        NumberFormat numberFormatter =
//                NumberFormat.getPercentInstance(this.currentLocale);
//        return numberFormatter.format(number);
//    }
//
//    public String getDate(long date, int style) {
//        DateFormat dateFormatter =
//                DateFormat.getDateInstance(style, this.currentLocale);
//        return dateFormatter.format(new Date(date));
//    }
//
//    public int compare(String source, String target) {
//        Collator collator = Collator.getInstance(this.currentLocale);
//        return collator.compare(source, target);
//    }
}
